<?php
/**
 * Created by : Sandi Rizky Kharisma (sandi.informatics08@gmail.com)
 * This Class Generated for CRUD purpose only
 */
class member extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        $this->load->library('auth');
        $this->load->library('base');
        $this->load->library('ajaxresponse');
        $this->load->library('datatables');
        $this->load->model('crud/m_member');
    }

    public function crud()
    {
        $this->auth->is_logged_in('form/login');
        $this->base->head_html('Tabel member');
        $this->load->view('crud/member');
    }

    public function get_personality()
    {
        $this->auth->is_logged_in('form/login');
        $id_anggota = $this->session->userdata("ID_ANGGOTA");
        $this->load->model('crud/m_anggota');
        $this->load->model('report/m_potongan');

        $this->response = new ajaxresponse();
        $this->response->data["personal"] = $this->m_anggota->get_one($id_anggota)->first_row();
        $this->response->data["rencana_potongan"] = $this->m_potongan->get_active($id_anggota)->result();
        
        echo json_encode($this->response);

    }

    public function get_all()
    {
        $this->auth->is_logged_in('form/login');
        $this->response = new ajaxresponse();
        $this->response->data = $this->m_member->get()->result();
        echo json_encode($this->response);
    }
    
    public function get($id)
    {
        $this->auth->is_logged_in('form/login');
        $this->response = new ajaxresponse();
        $this->response->data = $this->m_member->get_one($id)->result_array();
        echo json_encode($this->response);
    }

    public function add()
    {
        $this->auth->is_logged_in('form/login');
        $this->response = new ajaxresponse();

        $id_anggota = $this->input->post("ID_ANGGOTA");
        $isExist = $this->m_member->get_one($id_anggota);
        if(!$isExist)
            $this->response->data = $this->m_member->insert();

        echo json_encode($this->response);
    }

    public function update($id)
    {
        $this->auth->is_logged_in('form/login');
        $this->response = new ajaxresponse();
        $this->response->data = $this->m_member->update($id);
        echo json_encode($this->response);
    }
    
    public function delete($id)
    {
        $this->auth->is_logged_in('form/login');
        $this->response = new ajaxresponse();
        $this->response->data = $this->m_member->delete($id);
        echo json_encode($this->response);
    }
}
?>